﻿using System;
using System.Net;
using System.IO;
using System.Text;
using System.Collections.Generic;
using System.Collections;

namespace OneMake.Common
{
    public class Utils
    {
        public Utils()
        {
        }

        //获取目录及其子目录下的制定类型的文件
        //例:
        //  ArrayList files = new ArrayList();
        //  string[] filters = new string[] { ".jpg", ".png" };
        //  getFileList(@"c:\temp", filters, files);
        public void getFileList(string strBaseDir, string[] filters, ArrayList al)
        {
            DirectoryInfo di = new DirectoryInfo(strBaseDir);//获得目录信息
            

            //获得该目录下的指定类型的文件;
            FileInfo[] fiA = di.GetFiles("*.*");
            for (int j = 0; j < fiA.Length; j++)
            {
                foreach (string fi in filters)
                {
                    if (fiA[j].Extension.ToLower() == fi)
                    {
                        al.Add(fiA[j]);
                        break;
                    }
                }
            }

            //子目录递归
            DirectoryInfo[] diA = di.GetDirectories();//获得该目录下的所有子目录
            for (int i = 0; i < diA.Length; i++)
            {
                getFileList(diA[i].FullName, filters, al);
            }
        }
    }
}
